import { Fragment } from '@/components/Fragment'; import { Loader } from '@aws-amplify/ui-react'; import { LoaderDemo } from './demo'; import { DefaultLoaderExample, DeterminateLoaderExample, LoaderAccessibilityExample, LoaderColorExample, LoaderIsPercentageTextHiddenExample, LoaderSizesExample, LoaderVariationExample, LoaderThemeExample, } from './examples'; import { Example, ExampleCode } from '@/components/Example'; import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay'; import ThemeExample from '@/components/ThemeExample.mdx'; ## Demo ## Usage Import the Loader component and styles. ```jsx file=./examples/DefaultLoaderExample.tsx ``` ### Sizes Use the `size` prop to change the Loader size. Available options are `small`, `large`, and none (default). ```jsx file=./examples/LoaderSizesExample.tsx ``` ### Variation Loader comes in 2 variants, `linear` and none(default). Pass the `variation` prop and set it to either of these values. ```jsx file=./examples/LoaderVariationExample.tsx ``` ### Colors Pass `filledColor` and `emptyColor` props to color your own Loader. ```jsx file=./examples/LoaderColorExample.tsx ``` ### Determinate Most often loaders are indeterminate (looped) but may be determinate (percentage-based) when the system can calculate the size of the request — for example, when downloading a large file. To use a determinate loader, set `isDeterminate` to `true` and pass `percentage`. ```jsx file=./examples/DeterminateLoaderExample.tsx ``` To hide the percentage text, set `isPercentageTextHidden` to `true`. ```jsx file=./examples/LoaderIsPercentageTextHiddenExample.tsx ``` ### Accessibility The Loader is a SVG image with role set to `img` on the outer `` element. This will tell screen readers to just consider it as a single entity and describe it using the label, rather than trying to read out all the child nodes. You can give it a label by passing `ariaLabel` prop. ```jsx file=./examples/LoaderAccessibilityExample.tsx ``` ## CSS Styling ```tsx file=./examples/LoaderThemeExample.tsx ``` ### Target classes ### Global styling To override styling on all Loaders, you can set the Amplify CSS variables with the built-in `.amplify-loader` class. ```css /* styles.css */ .amplify-loader { --amplify-components-loader-stroke-filled-color: var(--amplify-colors-red-80); } ``` ```jsx import { Loader } from '@aws-amplify/ui-react'; import './styles.css'; ; ``` ### Local styling To override styling on a specific Loader, you can use (in order of increasing specificity): a class selector, data attributes, or style props. _Using a class selector:_ ```css /* styles.css */ .my-loader { width: 5rem; height: 5rem; } ``` ```jsx import { Loader } from '@aws-amplify/ui-react'; import './styles.css'; ; ``` _Using data attributes:_ ```css /* styles.css */ .amplify-loader[data-size='large'] { width: 5rem; height: 5rem; } ``` ```jsx import { Loader } from '@aws-amplify/ui-react'; import './styles.css'; ; ``` _Using style props:_ ```jsx import { Loader } from '@aws-amplify/ui-react'; ```